package review;

import java.util.Stack;

/*
* 两个栈实现一个队列
* */
public class QuestionOne {
    Stack<Integer> s1;
    Stack<Integer> s2;

    public QuestionOne(){
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int val){
        s1.push(val);
    }

    public int pop(){
        int result = -1;

        if (s2.isEmpty()&& !s1.empty()){
            while(s1.size()>0){
                s2.push(s1.pop());
            }
            result = s2.pop();
        }

        if (s1.isEmpty() && !s2.isEmpty()){
            while(s2.size()>0){
                s1.push(s2.pop());
            }
        }
        return result;
    }

    public static void main(String[] args) {
        QuestionOne one = new QuestionOne();
        one.push(1);
        System.out.println(one.pop());
        System.out.println(one.pop());
    }

}
